$('#logo').on('change', function () {
    var file = this.files[0];
    var formData = new FormData();
    formData.append('avatar', file);
    $.ajax({
        type: 'post',
        url: '/upload',
        data: formData,
        processData: false,
        contentType: false,
        success: function (res) {
            $('#hiddenLogo').val(res[0].avatar);
            $('#preview').attr('src', res[0].avatar)
        }
    })
})

$('#settingsForm').on('submit', function () {
    var formData = $(this).serialize();
    $.ajax({
        type: 'post',
        url: '/settings',
        data: formData,
        success: function () {
            location.reload();
        }
    })
    return false
})
$.ajax({
    type: 'get',
    url: '/settings',
    success: function (res) {
        if (res) {
            console.log(res);

            $('#hiddenLogo').val(res.logo);
            $('#preview').attr('src', res.logo);
            // 将网站标题显示在页面中 
            $('input[name="title"]').val(res.title);
            // 将是否开启评论功能显示在页面中
            $('input[name="comment"]').prop('checked', res.comment)
            // 将评论是否经过人工审核显示在页面中 
            $('input[name="review"]').prop('checked', res.review)
        }
    }
})